package com.xuecheng.managecmsclient.mq;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xuecheng.managecmsclient.service.CmsPageService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 监听MQ,接收页面发布的消息
 *
 * @author jl
 * @description
 * @date 2019-08-20 10:07
 */
@Component
public class ConsumerPostPage {
    @Autowired
    private CmsPageService cmsPageService;

    @RabbitListener(queues = {"${xc.mq.queue}"})
    public void listener(String msg) {
        //解析消息
        JSONObject jsonObject = JSON.parseObject(msg);
        String pageId = jsonObject.getString("pageId");
        //调用service方法将页面从GridFS中下载到服务器
        cmsPageService.savePageToServerPath(pageId);
    }
}
